package com.srd.phone.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.shengrongdai.srd.R;
import com.srd.phone.bean.AuditLoanDetail;
import com.srd.phone.mvp.presenters.UtilPresenter;
import com.srd.phone.utils.Constants;

/**
 * 审核中的借款标详情
 * &
 * 招标中的借款标详情
 */
public class AuditLoanDetailActivity extends BaseActivity{

    private RelativeLayout rl_load_type,rl_progress;
    private View line1, line2;
    private TextView tv_title_name, tv_type,tv_interest_rate, tv_money, tv_interest, tv_data,
            tv_data_no, tv_data_yes, tv_progress;

    private int id = 0;  // 24 test

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audit_loan_detail);

        initView();
        initData();
    }

    @Override
    public void initView() {
        super.initView();

        rl_load_type = (RelativeLayout)findViewById(R.id.rl_load_type);
        rl_progress = (RelativeLayout)findViewById(R.id.rl_progress);
        line1 = findViewById(R.id.line1);
        line2 = findViewById(R.id.line2);

        Intent intent = getIntent();
        String flag = intent.getStringExtra(Constants.TENDERLOAN);
        id = intent.getIntExtra("auditId", 0);
        if(flag.equals("auditLoan")){
            tv_common_title.setText("审核中的借款标详情");
            rl_load_type.setVisibility(View.GONE);
            rl_progress.setVisibility(View.GONE);
            line1.setVisibility(View.GONE);
            line2.setVisibility(View.GONE);
        }else{
            tv_common_title.setText("招标中的借款标详情");
            rl_load_type.setVisibility(View.VISIBLE);
            rl_progress.setVisibility(View.VISIBLE);
            line1.setVisibility(View.VISIBLE);
            line2.setVisibility(View.VISIBLE);
        }

        tv_title_name = (TextView)findViewById(R.id.tv_title_name);
        tv_type = (TextView)findViewById(R.id.tv_type);
        tv_money = (TextView)findViewById(R.id.tv_money);
        tv_interest_rate = (TextView)findViewById(R.id.tv_interest_rate);
        tv_interest = (TextView)findViewById(R.id.tv_interest);

        tv_data = (TextView)findViewById(R.id.tv_data);
        tv_data_no = (TextView)findViewById(R.id.tv_data_no);
        tv_data_yes = (TextView)findViewById(R.id.tv_data_yes);
        tv_progress = (TextView)findViewById(R.id.tv_progress);
    }

    private UtilPresenter utilPresenter;
    public void initData() {

        showWaitingDialog();
        presenter = new UtilPresenter(requestQueue, this);
        utilPresenter = (UtilPresenter)presenter;
        setUrlArrs(Constants.MYBMARK_INFO1);
        getData();

    }

    private void getData(){
        utilPresenter.accountDetail(Constants.MYBMARK_INFO1, id);
    }

    @Override
    public void returnData(String tag, String data) {
        super.returnData(tag, data);
        cancelWaitingDialog();
        if(Constants.MYBMARK_INFO1.equals(tag)){
            AuditLoanDetail info = AuditLoanDetail.parseData(data);
            if(info == null)  return;
            tv_title_name.setText(info.nm);
            tv_type.setText(info.tidm);
            tv_money.setText(info.moneys + "元");
            tv_interest_rate.setText(info.anyield + "%");
            tv_interest.setText(info.interest + "元"); // 利息
            tv_data.setText(info.cdata + "");
            tv_data_no.setText(info.cstfl + "");
            tv_data_yes.setText(info.csttr + "");
            tv_progress.setText(info.subsch + "%");
        }
    }

    @Override
    public void onError(String tag, VolleyError error) {
        super.onError(tag, error);
        cancelWaitingDialog();
    }
}